//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.eova.model;

import com.eova.common.base.BaseModel;
import com.jfinal.plugin.activerecord.Db;
import java.util.List;

public class Button extends BaseModel<Button> {
    private static final long serialVersionUID = 3481288366186459644L;
    public static final int FUN_QUERY = 1;
    public static final String FUN_QUERY_NAME = "查询";
    public static final String FUN_QUERY_UI = "query";
    public static final String FUN_QUERY_BS = "/grid/query";
    public static final int FUN_ADD = 2;
    public static final String FUN_ADD_NAME = "新增";
    public static final String FUN_ADD_UI = "/eova/widget/form/btn/add.html";
    public static final String FUN_ADD_BS = "/form/add";
    public static final int FUN_UPDATE = 3;
    public static final String FUN_UPDATE_NAME = "修改";
    public static final String FUN_UPDATE_UI = "/eova/widget/form/btn/update.html";
    public static final String FUN_UPDATE_BS = "/form/update";
    public static final int FUN_DELETE = 4;
    public static final String FUN_DELETE_NAME = "删除";
    public static final String FUN_DELETE_UI = "/eova/widget/form/btn/delete.html";
    public static final String FUN_DELETE_BS = "/grid/delete";
    public static final int FUN_DETAIL = 5;
    public static final String FUN_DETAIL_NAME = "查看";
    public static final String FUN_DETAIL_UI = "/eova/widget/form/btn/detail.html";
    public static final String FUN_DETAIL_BS = "/form/detail";
    public static final int FUN_IMPORT = 6;
    public static final String FUN_IMPORT_NAME = "导入";
    public static final String FUN_IMPORT_UI = "/eova/template/single/btn/import.html";
    public static final String FUN_IMPORT_BS = "/single_grid/import";
    public static final Button dao = new Button();

    public Button() {
    }

    public Button(String menuCode, int type) {
        String ui = null;
        String bs = null;
        String name = null;
        switch(type) {
            case 1:
                ui = "query";
                bs = "/grid/query";
                name = "查询";
                break;
            case 2:
                ui = "/eova/widget/form/btn/add.html";
                bs = "/form/add";
                name = "新增";
                break;
            case 3:
                ui = "/eova/widget/form/btn/update.html";
                bs = "/form/update";
                name = "修改";
                break;
            case 4:
                ui = "/eova/widget/form/btn/delete.html";
                bs = "/grid/delete";
                name = "删除";
                break;
            case 5:
                ui = "/eova/widget/form/btn/detail.html";
                bs = "/form/detail";
                name = "查看";
                break;
            case 6:
                ui = "/eova/template/single/btn/import.html";
                bs = "/single_grid/import";
                name = "导入";
        }

        this.set("menu_code", menuCode);
        this.set("name", name);
        this.set("ui", ui);
        this.set("bs", bs);
        this.set("order_num", Integer.valueOf(type));
        this.set("is_base", Boolean.valueOf(true));
    }

    public List<Button> queryByMenuCode(String menuCode, int rid) {
        return dao.queryByCache("select * from eova_button where menu_code = ? and ui <> ? and id in (select bid from eova_role_btn where rid = ?) order by order_num", new Object[]{menuCode, "query", Integer.valueOf(rid)});
    }
    public List<Button> queryByMenuCode(String menuCode, int rid,int group) {
        return dao.queryByCache("select * from eova_button where menu_code = ? and ui <> ? and id in (select bid from eova_role_btn where rid = ?) and group_num = ? order by order_num", new Object[]{menuCode, "query", Integer.valueOf(rid),Integer.valueOf(group)});
    }
    public boolean isExistButton(String menuCode, String bs, int groupNum) {
        String sql = "select count(*) from eova_button where menu_code = ? and bs = ? and group_num = ?";
        long count = Db.use("eova").queryLong(sql, new Object[]{menuCode, bs, Integer.valueOf(groupNum)}).longValue();
        return count != 0L;
    }

    public void deleteFunByMenuCode(String menuCode) {
        String sql = "delete from eova_button where is_base = 1 and ui <> \'query\' and menu_code = ?";
        Db.use("eova").update(sql, new Object[]{menuCode});
    }

    public void deleteByMenuCode(String menuCode) {
        String sql = "delete from eova_button where menu_code = ?";
        Db.use("eova").update(sql, new Object[]{menuCode});
    }

    public List<Button> findFunByMenuCode(String menuCode) {
        return this.find("select * from eova_button where ui <> \'query\' and menu_code = ?", new Object[]{menuCode});
    }

    public List<Button> findNoQueryByMenuCode(String menuCode) {
        String sql = "select * from eova_button where ui <> \'query\' and menu_code = ? order by group_num, order_num";
        return this.find(sql, new Object[]{menuCode});
    }

    public int getMaxOrderNum(String menuCode, int groupNum) {
        String sql = "select max(order_num) from eova_button where menu_code = ? and group_num = ?";
        return Db.use("eova").queryNumber(sql, new Object[]{menuCode, Integer.valueOf(groupNum)}).intValue();
    }
}
